/* *********
 *    Author: Jason He;
 *    Version: 0.0.1;
 *    Date: 2016-12-26;
 *    File: list-filter.js;
 ********* */

$(document).ready(function () {
	$("#reset").click(function () {
		$(".filter-single-select").find("a").removeClass("cur");
		$(".filter-mult-select").find("a").removeClass("active");
	});

	$(".filter-single-select").on("click", "a", function () {
		$(this).addClass("cur").parent().siblings().children().removeClass("cur");
	});
	$(".filter-mult-select").on("click", "a", function () {
		$(this).toggleClass("active");
	});

	$('#age-slider').nstSlider({
		"left_grip_selector": "#age-leftGrip",
		"right_grip_selector": "#age-rightGrip",
		"value_bar_selector": "#age-bar",
		"value_changed_callback": function (cause, leftValue, rightValue) {
			if (leftValue == 0 && rightValue == 8) {
			    $("#age-cur").text("不限");
			    $("#age-cur").attr('value', '');
			} else if (leftValue > 0 && rightValue == 8) {
			    $("#age-cur").text(leftValue + "年以上");
			    $("#age-cur").attr('value', '>' + leftValue);
			} else if (leftValue == 0 && rightValue < 8) {
			    $("#age-cur").text(rightValue + "年以下");
			    $("#age-cur").attr('value', '<' + rightValue);
			} else if (leftValue > 0 && rightValue < 8) {
			    $("#age-cur").text(leftValue + "-" + rightValue + "年");
			    $("#age-cur").attr('value', leftValue + "-" + rightValue);
			}
		}
	});
	$('#mileage-slider').nstSlider({
		"left_grip_selector": "#mileage-leftGrip",
		"right_grip_selector": "#mileage-rightGrip",
		"value_bar_selector": "#mileage-bar",
		"value_changed_callback": function (cause, leftValue, rightValue) {
			if (leftValue == 0 && rightValue == 15) {
			    $("#mileage-cur").text("不限");
			    $("#mileage-cur").attr('value','');
			} else if (leftValue > 0 && rightValue == 15) {
			    $("#mileage-cur").text(leftValue + "万公里以上");
			    $("#mileage-cur").attr('value', '>' + leftValue);
			} else if (leftValue == 0 && rightValue < 15) {
			    $("#mileage-cur").text(rightValue + "万公里以下");
			    $("#mileage-cur").attr('value', '<' + rightValue);
			} else if (leftValue > 0 && rightValue < 15) {
			    $("#mileage-cur").text(leftValue + "-" + rightValue + "万公里");
			    $("#mileage-cur").attr('value', leftValue + "-" + rightValue);
			}
		}
	});
	$('#engine-slider').nstSlider({
		"left_grip_selector": "#engine-leftGrip",
		"right_grip_selector": "#engine-rightGrip",
		"value_bar_selector": "#engine-bar",
		"rounding": 0.5,
		"value_changed_callback": function (cause, leftValue, rightValue) {
			if (leftValue == 0 && rightValue == 5) {
			    $("#engine-cur").text("不限");
			    $("#engine-cur").attr('value', '');
			} else if (leftValue > 0 && rightValue == 5) {
			    $("#engine-cur").text(leftValue + "升以上");
			    $("#engine-cur").attr('value', '>' + leftValue);
			} else if (leftValue == 0 && rightValue < 5) {
			    $("#engine-cur").text(rightValue + "升以下");
			    $("#engine-cur").attr('value', '<' + rightValue);
			} else if (leftValue > 0 && rightValue < 5) {
			    $("#engine-cur").text(leftValue + "-" + rightValue + "升");
			    $("#engine-cur").attr('value', leftValue + "-" + rightValue);
			}
		}
	});
});